<script>
	var dodelete='__URL__/dodelete';
</script>

<!--table部分-->
<div class='col-md-12'>

	<div class="panel panel-default">
	  <div class="panel-body">
	  	<div class='col-md-4'>
	    	<button class='btn btn-success btn-lg' id='export2xls' ><i class='glyphicon glyphicon-circle-arrow-down'></i> 导出结果到EXCEL</button><a target="_blank" id='export_a' style='display: none'><span id='export_span'>弹到新窗口</span></a>
	    </div>
	    <div class='col-md-4'>
	    	<!-- pt over -->
		    <button class='btn btn-info btn-lg triggerupload' ><i class='glyphicon glyphicon-circle-arrow-up'></i> 导入党员信息</button>
		    <!-- 必须是a标签 -->
		    <link rel="stylesheet" type="text/css" href="__PUBLIC__/etc/huploadify/html5uploader.css"/>
		    <script type="text/javascript" src="__PUBLIC__/etc/huploadify/jquery.html5uploader.js"></script>
		    <script>var dogivetail='__APP__/Hupldf/dogivetail'</script>
		    <script type="text/javascript">
		    $(function(){
		        $('#upload').html5uploader({
		            fileTypeExts:'application/vnd.ms-excel',
		            auto:true,
		            multi:false,
		            removeTimeout:0,
		            url:'__APP__/Hupldf/upload/folder/dataup',//
		            onUploadStart:function(){
		                //alert('开始上传');
		                $('#loading').trigger('click');
		                var timestamp = (new Date()).valueOf();
		            },
		            onInit:function(){
		                //alert('初始化');
		            },
		            onUploadComplete:function(file){
		                
		                $.post(
		                    '__URL__/dodaorudata',
		                    {},
		                    function(data){
		                        $('#loading_cancel').trigger('click');

		                        var dyls=data['dyls'];
		                        if(dyls.length==0){
		                        	alert('导入成功！');
		                        	window.location.reload();
		                        }else{
		                        	$('#rslt_panel').show();
		                        	var str='';
		                        	for(var i=0;i<dyls.length;i++){
		                        		dyo=dyls[i];
		                        		str=str+"<tr><td>"+dyo['xuhao']+"</td><td>"+dyo['dwnm']+"</td><td>"+dyo['dzbnm']+"</td><td>"+dyo['dynm']+"</td><td>"+dyo['leibienm']+"</td><td>"+dyo['jieduannm']+"</td><td>"+dyo['beizhunm']+"</td><td>"+dyo['guanxibiandongnm']+"</td><td>"+dyo['str_error']+'</td></tr>';
		                        	}
		                        	$('#rslt_tbody').html(str);
		                        	alert('错误信息已经展示，其他数据则导入成功，刷新可以显示新数据！');
		                        }

		                        
		                        
		                    },
		                    'json'
		                );
		            }
		        });
		    });
		    </script>
		    <div id="upload" style='display:none'></div>
			<script>
			$(function(){
			    $('.triggerupload').click(function(){
			        $('#uploadfilebtn').trigger('click');
			    });
			})
			</script>
	    </div>
	    <div class='col-md-4'>
	    	<button class='btn btn-warning btn-lg' onclick="window.location.reload()" ><i class='glyphicon glyphicon-refresh'></i> 刷新数据</button>
	    </div>

	  </div>
	</div>
	<div class="panel-body" style="display:none" id='rslt_panel'>
		<div class="panel-body">
			<table class='table table-hover table-striped table-bordered'>
				<thead><th>表中序号</th><th>党委</th><th>党支部</th><th>姓名</th><th>类别</th><th>阶段</th><th>备注</th><th>关系变动</th><th>错误原因</th></thead>
				<tbody id='rslt_tbody'></tbody>
			</table>
		</div>
	</div>
	<!--开始-->
	<table class='table table-hover table-striped table-bordered' id='NBtb'>
		<thead>
			<tr style="background-color: #337ab7;color:#fff">
				<th>序号</th>
				<volist name='thls' id='thv'>
					<th>{$thv}</th>
				</volist>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<volist name='mls' id='mv'>
				<tr>
					<td>{$pagestart+$i}</td>
					<?php foreach ($mv as $key => $value) {
						if(!in_array($key,$hide_fld)){
					?>
						<td>{$value}</td>
					<?php 
						}
					} ?>
					<td>
					<?php if($atho['athv']){ ?><a class='btn btn-success btn-sm' href="__URL__/view/id/<?php echo $mv[$lowmdmk.'id'] ?>">查看</a><?php } ?>
					<?php if($atho['athm']){ ?><a class='btn btn-warning btn-sm' href="__URL__/update/id/<?php echo $mv[$lowmdmk.'id'] ?>">修改</a><?php } ?>
					<?php if($atho['athd']){ ?><a class='btn btn-danger btn-sm' onclick="dlt(<?php echo $mv[$lowmdmk.'id'] ?>)" >删除</a><?php } ?>
					</td>
				</tr>
			</volist>
			
		</tbody>
	</table>
	
	<!--结束-->
	{$page}
	<br><br><?php if($atho['atha']){ ?><a class='btn btn-primary' href='__URL__/update/id/0'>添加</a><?php } ?>
</div>

<script type="text/javascript">

</script>
<script type="text/javascript">$("#NBtb thead").smartFloatTB();</script>
<script type="text/javascript">
function dlt(id){
	if(confirm("{$deleteconfirm}")){
		$.ajax({
            'type': 'GET',
            'url':dodelete,
            'async':false,  
            'contentType': 'application/json',
            'data': {'id':id},
            'dataType': 'json',
            'success': function(data) {
            	alert('删除成功！');
            	window.location.reload();
                console.log("success");
            },
            'error':function() {
                console.log("error");
            }
        });
	}
}
</script>
<script type="text/javascript">
$(function(){
	$('#export2xls').click(function(){
	  
	  //处理cdt
	  var cdtls=$('.cdt');
	  for(var i=0;i<cdtls.size();i++){
	    cdto=cdtls[i];var id_cdt=$(cdto).attr('id');
	    if($.trim($(cdto).val())!=''){
	      obj[id_cdt]=$.trim($(cdto).val());
	    }
	  }
	  //处理spccdt
	  var spccdtls=$('.spccdt');
	  for(var i=0;i<spccdtls.size();i++){
	    spccdto=spccdtls[i]; 
	    var cls=$(spccdto).attr('class');
	    if(cls.indexOf('info')!=-1){
	      obj[i+'_nb_spccdt']=$(spccdto).val();
	    }
	  }
	  //处理fld,未选中的fld需要从里头除名
	  var fldls=$('.fld');
	  for(var i=0;i<fldls.size();i++){
	    fldo=fldls[i];
	    if($(fldo).is(':checked')==false){
	      var id_fld=$(fldo).attr('id');
	      id_fld=id_fld.split('_nb_fld')['0'];
	      fldu=fldu.replace(id_fld+'-','');
	    }
	  }
	  obj['nb_fld']=fldu;
	  
	  //处理odr
	  var odrls=$('.odr');
	  for(var i=0;i<odrls.size();i++){
	    odro=odrls[i];var id_odr=$(odro).attr('id');
	    if($(odro).val()!=''){
	      obj[id_odr]=$(odro).val();
	    }
	  }
	  //处理lmt
	  obj['nb_lmt']=$('#nb_lmt').val();

	  //处理mdmk
	  obj['nb_mdmk']="{$mdmk}";

	  $.ajax({
	      'type': 'GET',
	      'url':dosearch,
	      'async':false,  
	      'contentType': 'application/json',
	      'data': obj,
	      'dataType': 'json',
	      'success': function(data) {
	      	var url=data['url'];
	      	//把query给替换掉
	      	url=url.replace("query", "export");
	        $('#export_a').attr('href',url);
	       	$('#export_span').trigger('click');
	        console.log("success");
	      },
	      'error':function() {
	        console.log("error");
	      }
	  });
	})

	

})
</script>
